#include <QDebug>

#include "test_plugin_manager.h"

namespace
{
constexpr char loadFolder[] = "/home/snow/snow/code/kylin-os-manager/test/build/plugins_binary_dir/plugin-template";
}

namespace KyOsManagerTest
{

PluginManager::PluginManager() : m_manager(new kyplugin::KyPlugin)
{
    redisterType();
    loadPlugin();
}

PluginManager::~PluginManager()
{
    if (m_manager != nullptr) {
        delete m_manager;
        m_manager = nullptr;
    }
}

void PluginManager::redisterType(void)
{
    if (m_manager != nullptr) {
        m_manager->acceptProviderType<KyManagerPluginProvider>();
    }

    return;
}

void PluginManager::loadPlugin(void)
{
    if (m_manager != nullptr) {
        m_manager->loadFromFolder(loadFolder);
    }

    return;
}

QVector<KyManagerPluginProvider *> PluginManager::getProviders(void)
{
    std::vector<KyManagerPluginProvider *> providers;
    if (m_manager != nullptr) {
        m_manager->getProviders(providers);
    }

    return QVector<KyManagerPluginProvider *>::fromStdVector(providers);
}

} // namespace KyOsManagerTest